import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ytbusiness/widgets/widgets.dart';

import 'package:ytbusiness/utils/screen_adaptation.dart';

//提现
class Withdrawal extends StatefulWidget {
  @override
  _WithdrawalState createState() => _WithdrawalState();
}

class _WithdrawalState extends State<Withdrawal> {
  List<String> _keyboard = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]; //键盘
  TextEditingController _moneyEC = TextEditingController();
  bool _keyIsShow = false;
  List<String> bankLists = [
    '中国工商银行储蓄卡(0241)',
    '中国工商银行储蓄卡(0242)',
    '中国工商银行储蓄卡(0243)',
    '中国工商银行储蓄卡(0244)',
    '中国工商银行储蓄卡(0245)',
    '中国工商银行储蓄卡(0246)',
    '',
  ]; // 银行类别(已绑定)
  String chooseBankStr = '中国工商银行储蓄卡(0241)';

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        print('隐藏键盘⌨️,隐藏键盘⌨️,');
        FocusScope.of(context).requestFocus(FocusNode());
      },
      child: Scaffold(
        appBar: customAppBar(context, title: "提现"),
        body: Container(
          color: Color(0xfff5f5f5),
          child: Column(
            children: [
              // 银行卡类型
              InkWell(
                onTap: () {
                  print('银行卡类型  选择到账方式  点击事件');
                  _bouncedBottomSheet(
                    context: context,
                  );
                },
                child: Container(
                  margin: EdgeInsets.only(top: setWidth(15)),
                  padding: EdgeInsets.symmetric(horizontal: setWidth(15)),
                  height: setWidth(80),
                  color: Colors.white,
                  child: Row(
                    children: [
                      Image.asset(
                        'assets/images/ICBC_image.png',
                        width: setWidth(44),
                        height: setWidth(44),
                        fit: BoxFit.fill,
                      ),
                      SizedBox(
                        width: setWidth(9),
                      ),
                      Expanded(
                        child: Container(
                          height: setWidth(80),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                '工商银行',
                                style: TextStyle(
                                  color: Color(0xff010015),
                                  fontSize: setSp(15),
                                ),
                              ),
                              SizedBox(
                                height: setWidth(3),
                              ),
                              Text(
                                '尾号 6343  储蓄卡',
                                style: TextStyle(
                                  color: Color(0xff595959),
                                  fontSize: setSp(14),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                      Image.asset(
                        'assets/images/right_go.png',
                        width: setWidth(9),
                        height: setWidth(16.5),
                        fit: BoxFit.cover,
                      ),
                    ],
                  ),
                ),
              ),
              // 提现金额
              Container(
                margin: EdgeInsets.only(top: setWidth(15)),
                padding: EdgeInsets.symmetric(
                  horizontal: setWidth(15),
                  vertical: setWidth(22),
                ),
                height: setWidth(180),
                color: Colors.white,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      '提现金额',
                      style: TextStyle(
                        color: Color(0xff333333),
                        fontSize: setSp(15),
                      ),
                    ),
                    Row(
                      children: [
                        Text(
                          '￥',
                          style: TextStyle(
                            color: Color(0xff333333),
                            fontSize: setSp(24),
                          ),
                        ),
                        Expanded(
                          child: TextFormField(
                            controller: _moneyEC,
                            style: TextStyle(fontSize: setSp(24)),
                            maxLines: 1,
                            textInputAction: TextInputAction.search,
                            keyboardType: TextInputType.number,
                            readOnly: true,
                            showCursor: true,
                            onTap: () {
                              setState(() {
                                _keyIsShow = true;
                              });
                            },
                            decoration: InputDecoration(
                              hintText: '提现金额',
                              contentPadding: EdgeInsets.only(
                                left: setWidth(10),
                                top: setWidth(10),
                                bottom: setWidth(10),
                              ),
                              isDense: true,
                              border: InputBorder.none,
                              focusedBorder: InputBorder.none,
                              enabledBorder: InputBorder.none,
                            ),
                          ),
                        ),
                      ],
                    ),
                    Row(
                      children: [
                        Text(
                          '可用余额0.00元',
                          style: TextStyle(
                            color: Color(0xff999999),
                            fontSize: setSp(15),
                          ),
                        ),
                        SizedBox(
                          width: setWidth(5),
                        ),
                        Text(
                          '全部提现',
                          style: TextStyle(
                            color: Color(0xffff4d4d),
                            fontSize: setSp(15),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
              // 确认提现 按钮
              InkWell(
                onTap: () {
                  print('确认提现事件!!!!');
                },
                child: Container(
                  margin: EdgeInsets.only(
                    left: setWidth(30),
                    top: setWidth(30),
                    right: setWidth(30),
                  ),
                  height: setWidth(44),
                  decoration: BoxDecoration(
                    color:
                        Color(0xff1a79ff).withOpacity(//!state.isColors ? 0.4 :
                            1),
                    borderRadius: BorderRadius.circular(setWidth(5)),
                  ),
                  alignment: Alignment.center,
                  child: Text(
                    '确认提现',
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: setSp(15),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
        bottomSheet: Container(
          child: Offstage(
            offstage: !_keyIsShow,
            child: ListView(
              physics: NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              children: [
                //显示隐藏键盘
                GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () {
                    FocusScope.of(context).requestFocus(FocusNode());
                    setState(() {
                      _keyIsShow = !_keyIsShow;
                    });
                  },
                  child: Container(
                    padding: EdgeInsets.only(
                        top: setWidth(17), bottom: setWidth(17)),
                    decoration: BoxDecoration(
                      color: Colors.white,
                      border: Border(
                        top: BorderSide(
                          width: setWidth(0.5),
                          color: Color(0xffF5F5F5),
                        ),
                      ),
                    ),
                    child: Container(
                      width: setWidth(16),
                      height: setWidth(9),
                      child: Image.asset("assets/images/pay_down.png"),
                    ),
                  ),
                ),
                Container(
                  color: Color(0xffE3E8EE),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Expanded(
                        child: Column(
                          children: [
                            Wrap(
                              children: _keyboard
                                  .asMap()
                                  .map((key, value) {
                                    return MapEntry(
                                      key,
                                      GestureDetector(
                                        onTap: () {},
                                        child: Container(
                                          alignment: Alignment.center,
                                          width: setWidth(94),
                                          height: setWidth(60),
                                          decoration: BoxDecoration(
                                            color: Colors.white,
                                            border: Border(
                                              top: BorderSide(
                                                color: Color(0xffE6E7E9),
                                                width: setWidth(0.5),
                                              ),
                                              right: BorderSide(
                                                color: Color(0xffE6E7E9),
                                                width: setWidth(0.5),
                                              ),
                                            ),
                                          ),
                                          child: Text(
                                            value,
                                            style: TextStyle(
                                              color: Color(0xff333333),
                                              fontSize: setSp(30),
                                            ),
                                          ),
                                        ),
                                      ),
                                    );
                                  })
                                  .values
                                  .toList(),
                            ),
                            Row(
                              children: [
                                GestureDetector(
                                  onTap: () {},
                                  child: Container(
                                    alignment: Alignment.center,
                                    width: setWidth(188),
                                    height: setWidth(60),
                                    decoration: BoxDecoration(
                                      color: Colors.white,
                                      border: Border(
                                        top: BorderSide(
                                          color: Color(0xffE6E7E9),
                                          width: setWidth(0.5),
                                        ),
                                        right: BorderSide(
                                          color: Color(0xffE6E7E9),
                                          width: setWidth(0.5),
                                        ),
                                      ),
                                    ),
                                    child: Text(
                                      "0",
                                      style: TextStyle(
                                        color: Color(0xff333333),
                                        fontSize: setSp(30),
                                      ),
                                    ),
                                  ),
                                ),
                                GestureDetector(
                                  onTap: () {},
                                  child: Container(
                                    alignment: Alignment.center,
                                    width: setWidth(94),
                                    height: setWidth(60),
                                    decoration: BoxDecoration(
                                      color: Colors.white,
                                      border: Border(
                                        top: BorderSide(
                                          color: Color(0xffE6E7E9),
                                          width: setWidth(0.5),
                                        ),
                                        right: BorderSide(
                                          color: Color(0xffE6E7E9),
                                          width: setWidth(0.5),
                                        ),
                                      ),
                                    ),
                                    child: Text(
                                      ".",
                                      style: TextStyle(
                                        color: Color(0xff333333),
                                        fontSize: setSp(30),
                                      ),
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ],
                        ),
                      ),
                      Container(
                        width: setWidth(93),
                        child: Column(
                          children: [
                            GestureDetector(
                              onTap: () {},
                              child: Container(
                                height: setWidth(60),
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                  color: Colors.white,
                                  border: Border(
                                    top: BorderSide(
                                      color: Color(0xffE6E7E9),
                                      width: setWidth(0.5),
                                    ),
                                    right: BorderSide(
                                      color: Color(0xffE6E7E9),
                                      width: setWidth(0.5),
                                    ),
                                  ),
                                ),
                                child: Image.asset(
                                  "assets/images/black_pay_delete.png",
                                  width: setWidth(27),
                                  height: setWidth(19),
                                  fit: BoxFit.cover,
                                ),
                              ),
                            ),
                            GestureDetector(
                              onTap: () {
                                print('确定 按钮点击事件!!!!');
                              },
                              child: Container(
                                height: setWidth(181),
                                alignment: Alignment.center,
                                color: Color(0xff00C65F),
                                child: Text(
                                  "确定",
                                  style: TextStyle(
                                    color: Colors.white,
                                    fontSize: setSp(18),
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  Future _bouncedBottomSheet({
    BuildContext context,
  }) {
    return showModalBottomSheet(
      backgroundColor: Colors.white,
      context: context,
      builder: (ctx) {
        return Container(
          height: ScreenUtil.bottomBarHeight + setWidth(367),
          child: Column(
            children: [
              Container(
                height: setWidth(55),
                decoration: BoxDecoration(
                  border: Border(
                    bottom: BorderSide(
                      color: Color(0xffeeeeee),
                    ),
                  ),
                ),
                alignment: Alignment.center,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    InkWell(
                      onTap: () {
                        Navigator.pop(context);
                      },
                      child: Container(
                        padding: EdgeInsets.only(
                          left: setWidth(15),
                          top: setWidth(19.5),
                          right: setWidth(15),
                          bottom: setWidth(19.5),
                        ),
                        child: Image.asset(
                          'assets/images/leftBlack_image.png',
                          width: setWidth(9),
                          height: setWidth(16),
                          fit: BoxFit.fill,
                        ),
                      ),
                    ),
                    Text(
                      '选择到账方式',
                      style: TextStyle(
                        color: Color(0xff010015),
                        fontSize: setSp(16),
                      ),
                    ),
                    Container(
                      height: setWidth(55),
                      width: setWidth(39),
                    ),
                  ],
                ),
              ),
              Container(
                height: setWidth(255),
                child: ListView(
                  children: bankLists
                      .asMap()
                      .map((index, model) {
                        return MapEntry(
                          index,
                          model != ''
                              ? InkWell(
                                  onTap: () {
                                    Navigator.pop(context);
                                  },
                                  child: Container(
                                    height: setWidth(55),
                                    padding: EdgeInsets.only(
                                      left: setWidth(15),
                                    ),
                                    child: Row(
                                      children: [
                                        Image.asset(
                                          'assets/images/ICBC_image.png',
                                          width: setWidth(25),
                                          height: setWidth(25),
                                          fit: BoxFit.fill,
                                        ),
                                        SizedBox(
                                          width: setWidth(14),
                                        ),
                                        Expanded(
                                          child: Container(
                                            height: setWidth(55),
                                            decoration: BoxDecoration(
                                              border: Border(
                                                bottom: BorderSide(
                                                  color: Color(0xffeeeeee),
                                                  width: setWidth(0.5),
                                                ),
                                              ),
                                            ),
                                            padding: EdgeInsets.only(
                                              right: setWidth(25),
                                            ),
                                            child: Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment
                                                      .spaceBetween,
                                              children: [
                                                Text(
                                                  model,
                                                  style: TextStyle(
                                                    color: Color(0xff010015),
                                                    fontSize: setSp(14),
                                                  ),
                                                ),
                                                Offstage(
                                                  offstage:
                                                      chooseBankStr != model,
                                                  child: Image.asset(
                                                    'assets/images/check_pay.png',
                                                    width: setWidth(22),
                                                    height: setWidth(15.5),
                                                    fit: BoxFit.fill,
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                )
                              : InkWell(
                                  onTap: () async {
                                    print('添加银行卡 点击事件!!!');
                                    var result = await Navigator.pushNamed(
                                        context, 'add_bank_card');
                                    print(
                                        '添加银行卡 点击事件!!! 添加银行卡 点击事件!!! 返回🔙 result = $result');
                                  },
                                  child: Container(
                                    height: setWidth(55),
                                    padding: EdgeInsets.only(
                                      left: setWidth(15),
                                    ),
                                    child: Row(
                                      children: [
                                        Image.asset(
                                          'assets/images/add_bank_card.png',
                                          width: setWidth(25),
                                          height: setWidth(25),
                                          fit: BoxFit.fill,
                                        ),
                                        SizedBox(
                                          width: setWidth(14),
                                        ),
                                        Expanded(
                                          child: Container(
                                            height: setWidth(55),
                                            padding: EdgeInsets.only(
                                              right: setWidth(25),
                                            ),
                                            child: Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment
                                                      .spaceBetween,
                                              children: [
                                                Text(
                                                  '添加银行卡',
                                                  style: TextStyle(
                                                    color: Color(0xff010015),
                                                    fontSize: setSp(14),
                                                  ),
                                                ),
                                                Image.asset(
                                                  'assets/images/right_go.png',
                                                  width: setWidth(9),
                                                  height: setWidth(16.5),
                                                  fit: BoxFit.cover,
                                                ),
                                              ],
                                            ),
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                ),
                        );
                      })
                      .values
                      .toList(),
                ),
              ),
              Container(
                height: setWidth(8),
                color: Color(0xffe9e9eb),
              ),
              InkWell(
                onTap: () {
                  print('取消取消取消取消取消 点击事件!!!!');
                  Navigator.pop(context);
                },
                child: Container(
                  color: Colors.white,
                  height: setWidth(49),
                  alignment: Alignment.center,
                  child: Text(
                    '取消',
                    style: TextStyle(
                      color: Color(0xff323232),
                      fontSize: setSp(16),
                    ),
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
